package kt.com.bilin.coin.ui.activity

import android.view.View
import android.view.ViewGroup
import com.alibaba.android.arouter.facade.annotation.Route
import com.bilin.coin.R
import com.bilin.coin.databinding.ItemMyMessageBinding
import com.bilin.coin.databinding.ItemRechargeRecordBinding
import kotlinx.android.synthetic.main.activity_base_refresh.*
import kt.com.bilin.coin.api.API_SERVICE
import kt.com.bilin.coin.api.toData
import kt.com.bilin.coin.bean.RechargeRecordBean
import kt.com.bilin.coin.common.PATH_RECHARGE_RECORD
import kt.com.bilin.coin.common.getString
import kt.com.bilin.coin.ui.adapter.BaseRecyclerAdapter
import kt.com.bilin.coin.ui.adapter.BaseViewHolder
import kt.com.bilin.coin.utils.Logger

@Route(path = PATH_RECHARGE_RECORD)
class RechargeRecordActivity : BaseRefreshActivity<RechargeRecordBean>() {
    override fun initView() {
        titleView.titleStr = R.string.text_recharge_record.getString()
        mBaseRecyclerAdapter = RechargeRecordAdapter()
        super.initView()
    }

    override fun onReload() {
        launchUI({ API_SERVICE.rechargeList(mRefreshHelper.page).toData()?.records }, mRefreshHelper.handApiObserver())
    }

    inner class RechargeRecordAdapter : BaseRecyclerAdapter<BaseViewHolder<ItemRechargeRecordBinding>, RechargeRecordBean>() {
        override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(ItemRechargeRecordBinding.inflate(getLayoutInflate(parent.context), parent, false))
        override fun onBindViewHolder(holder: BaseViewHolder<ItemRechargeRecordBinding>, bean: RechargeRecordBean, position: Int) {
            Logger.e("==>${bean}")
            holder.mViewBinding.run {
                bean.run {
                    tvMoney.text = getString(R.string.text_recharge_record_rmb, cardNum)
                    tvCreateTime.text = createTime
                    tvPhone.text = phone
                    tvAmount.text = getAmountText()
                    tvStatus.text = getStatusText()
                    tvFee.text = "${fee.toEngineeringString()}JDC"
                    setViewClick(position, root)
                }
            }
        }
    }
}